package com.cheng.lesson03;

import java.io.IOException;
import java.net.*;
import java.net.DatagramSocket;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.SocketException;
//发送端
public class UdpClientDemon01 {
    public static void main(String[] args) throws IOException {
        //1.建立socket连接
        DatagramSocket socket = new DatagramSocket();
        //2.建立数据包
        //发送的地址
        String msg = "你好，万里顾一程";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port=8080;

                                                      //数据，                数据的长度               发送的地址
        DatagramPacket packet = new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,localhost,port);

        //3.发送包
        socket.send(packet);
        //关闭资源
        socket.close();
    }
}
